/**
 *Class DeleteScreen
 *
 * version 1.0
 *
 * @author Jin Kit Chua
 * @version 20130319 V1.0
 */
package ch.zbw.iCoach.kit;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class DeleteScreen {

	private WelcomeScreen ws;
	private Languages la;

	private JFrame mainFrame;

	private JButton ok;
	private JButton cancel;

	private JLabel msg;
	private JLabel msg1;

	private JPanel buttonPanel;
	private JPanel msgPanel;

	private String first;
	private String last;

	/**
	 * 
	 * @param ws reference to the welcomescreen for deleting the user
	 * @param f String for the first name 
	 * @param l String for the last name 
	 * @param la reference for the translation
	 */
	public DeleteScreen(WelcomeScreen ws, String f, String l, Languages la) {
		this.ws = ws;
		this.first = f;
		this.last = l;
		this.la = la;

		this.mainFrame = new JFrame("Delete");

		this.ok = new JButton("Ok");
		this.cancel = new JButton("Cancel");

		this.buttonPanel = new JPanel();
		this.msgPanel = new JPanel();

		this.msg = new JLabel();
		this.msg1 = new JLabel("     " + this.first + " " + this.last);

		paint();
	}

	public void paint() {

		this.mainFrame.setBackground(Color.lightGray);
		this.mainFrame.setResizable(false);

		String tempLang = this.la.switchLangDeleteScreen();
		String[] parts = tempLang.split(",");
		String msg = parts[0];
		String buttonOk = parts[1];
		String buttonCancel = parts[2];
		String title = parts[3];

		this.msg.setText(msg);
		this.ok.setText(buttonOk);
		this.cancel.setText(buttonCancel);
		this.mainFrame.setTitle(title);

		this.mainFrame.setLayout(new BorderLayout(10, 20));
		this.buttonPanel.setLayout(new GridLayout(1, 4, 20, 20));
		this.msgPanel.setLayout(new GridLayout(2, 1, 20, 20));

		this.buttonPanel.add(this.ok);
		this.buttonPanel.add(this.cancel);

		this.msgPanel.add(this.msg);
		this.msgPanel.add(this.msg1);
		this.mainFrame.add(this.buttonPanel, BorderLayout.SOUTH);
		this.mainFrame.add(this.msgPanel, BorderLayout.CENTER);

		this.mainFrame.setSize(400, 250);
		this.mainFrame.setVisible(true);
		this.mainFrame.setLocation(650, 400);

		this.ok.addActionListener(new ActionListenerOk());
		this.cancel.addActionListener(new ActionListenerCancel());
	}

	class ActionListenerCancel implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			mainFrame.dispose();
		}
	}

	class ActionListenerOk implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			mainFrame.dispose();
			ws.DeleteUser();

		}
	}
}